import {baseUrl} from "@/config/env";
import website from "../../config/website";

function createObj(key, val) {
    let result = {}
    if (!key) {
        return result;
    }
    result[key] = val
    return result
}


export default () => {
    return {
        translate: false,
        searchLabelWidth: 100,
        excelBtn: true,
        labelWidth: 110,
        selection: true,
        tip: false,
        index: true,
        align: 'center',
        headerAlign: 'center',
        menuType: 'menu',
        menuPosition: "right",
        border: true,
        stripe: true,
        searchIndex: 2,
        searchMenuSpan: 6,
        submitText: "保 存",
        searchIcon: true,
        permissionBtn: {
            addBtn: 'sys:menu:add',
            editBtn: 'sys:menu:edit',
            viewBtn: 'sys:menu:info',
            delBtn: 'sys:menu:delete',
            delsBtn: 'sys:menu:deletes',
            dataRuleBtn: 'sys:dataRule:list'
        },
        column: [
            {
                label: '父级',
                prop: 'parentId',
                span: 24,
                type: "tree",
                dicUrl: baseUrl + '/start/sysMenu/AllMenu',
                dicQuery: {
                    isTree: true
                },
                filters: true,
                filterable: true,
                showColumn: false,
                props: {
                    label: "menuLabel",
                    value: "id",
                },
                control: (val, form) => {
                    let result = {
                        menuPosition: {
                            display: true,
                        },
                        parentId: {}
                    }
                    result.menuPosition.display = ["", 0, undefined, null].includes(val)
                    result.parentId.span = result.menuPosition.display ? 12 : 24
                    return result
                },
            },
            {
                label: '菜单位置',
                span: 12,
                prop: 'menuPosition',
                type: "select",
                dicData: [
                    {label: "左边", value: "left"},
                    {label: "顶部", value: "top"},
                ],
                align: 'left',
                rules: [{
                    message: "请选择菜单位置",
                    required: true,
                    trigger: "blur"
                }]
            },
            {
                label: '名称',
                span: 12,
                prop: 'menuLabel',
                width: 180,
                align: 'left',
                rules: [{
                    message: "请输入菜单名称",
                    required: true,
                    trigger: "blur"
                }]
            },

            {
                label: '类型',
                span: 12,
                prop: 'menuType',
                type: 'select',
                width: 60,
                rules: [{
                    message: "请输入选择菜单类型",
                    required: true,
                    trigger: "blur"
                }],
                control: (val, form) => {
                    if (val === undefined || val === null || val === '') {
                        form.menuType = 0;
                        return {}
                    }
                    let display = val === 0
                    let result = {}
                    result.menuIcon = createObj("menuIcon", display);
                    result.menuPath = createObj("menuPath", display);
                    result.menuOpenType = createObj("menuOpenType", display);
                    result.menuKeepAlive = createObj("menuKeepAlive", display);
                    result.display = createObj("display", display);
                    return result
                },
                dicData: [{
                    label: '菜单',
                    value: 0
                }, {
                    label: '按钮',
                    value: 1
                }],
            },
            {
                label: '路径',
                prop: 'menuPath',
                span: 24,
                display: true,
                align: 'left',
                rules: [{
                    message: "请输入访问路径",
                    required: true,
                    trigger: "blur"
                }]
            },
            {
                label: '前端组件',
                prop: 'menuComponent',
                span: 24,
                display: true,
                showColumn: false,
            },
            {
                label: '权限编码',
                span: 24,
                prop: 'menuCode',
                align: 'left'
            },

            {
                label: '图标',
                type: 'icon',
                span: 24,
                prop: 'menuIcon',
                iconList: website.iconTabs,
                display: true,
                width: 60,

            },
            {
                label: '打开方式',
                type: 'select',
                span: 24,
                prop: 'menuOpenType',
                iconList: website.iconTabs,
                display: true,
                dicData: [
                    {label: "默认", desc: "内部", value: 0},
                    {label: "外部新窗口", desc: "浏览器新窗口打开", value: 1},
                ],
                width: 60,

            },
            {
                label: '页面缓存',
                type: 'select',
                span: 24,
                prop: 'menuKeepAlive',
                display: true,
                dicData: [
                    {label: "否", value: 0},
                    {label: "是", value: 1},
                ],
                width: 60,
            },
            {
                label: "是否启用",
                span: 12,
                prop: 'enable',
                type: "radio",
                dicData: [
                    {label: "是", value: 1},
                    {label: "否", value: 0},
                ]
            },
            {
                label: '是否显示',
                span: 12,
                prop: 'display',
                type: "radio",
                dicData: [
                    {label: "是", value: 1},
                    {label: "否", value: 0},
                ]
            },
            {
                label: '序号',
                prop: 'menuSort',
                span: 24,
                type: "number",
                value: 0,
                showColumn: false,
            },
        ]
    }
}
